/* rsscxr.p - SCHEDULE ORDER RESPONSIBILITY-OWNING PROGRAM                    */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.4 $                                                           */
/*                                                                            */
/* This routine provides the procedures which are executed as a result of the */
/* call from the appropriate Data Type Controllers / structured programs      */
/* It contains most of the business logic pertaining to Schedule Order        */
/*                                                                            */
/* Revision: 1.3  BY:G.Latha          DATE: 03/23/00   ECO: *N03T*            */
/* Revision: 1.3  BY:Hemanth Ebenezer  DATE: 03/23/00   ECO: *N0DK*           */
/* Revision: 1.3  BY:Hemanth Ebenezer  DATE: 08/12/00   BY: *N0KP* myb        */
/* $Revision: 1.4 $      BY: Murali Ayyagari   DATE: 10/24/00  ECO: *N0V1*      */
/*                                                                            */
/*V8:ConvertMode=NoConvert                                                    */


{mfdeclre.i}
{pxmaint.i}


/* Define Handles for the programs. */
{pxphdef.i rsscxr1}
/* End Define Handles for the programs. */


/*============================================================================*/
PROCEDURE checkIfItemOnScheduleOrder:
   /*---------------------------------------------------------------------------
   Purpose:     TO CHECK IF IF SCHEDULE ORDER EXISTS FOR THE ITEM
   Exceptions:  NONE
   Notes:
   History:
   ---------------------------------------------------------------------------*/
   define input parameter  pItemId    as character no-undo.
   define output parameter pReference as character no-undo initial "".

   do on error undo, return error {&GENERAL-APP-EXCEPT}:

      for first scx_ref
         fields(scx_part scx_po)
         where scx_part = pItemId
         no-lock:
      end. /* for first scx_ref */
      if available scx_ref then
         pReference = scx_po.

   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* checkIfItemOnScheduleOrder */

/* extract from poporca4.p */
/* ========================================================================== */
/* *************************** INTERNAL PROCEDURES ************************** */
/* ========================================================================== */


/*mtt*/
/*============================================================================*/
PROCEDURE getOpenScheduleQuantity :
/*------------------------------------------------------------------------------
<Comment1>
rsscxr.p
getOpenScheduleQuantity (
   output integer pDivisor,
   output integer pOpenQty,
   input date pEffDate,
    Buffer pPod_det)

Parameters:
   pDivisor -
   pOpenQty -
   pEffDate -
   pPod_det -

Exceptions:

PreConditions:

PostConditions:

</Comment1>
<Comment2>
Notes:

</Comment2>
<Comment3>
History:

</Comment3>
------------------------------------------------------------------------------*/
   define output parameter pDivisor as integer no-undo.
   define output parameter pOpenQty as integer no-undo.
   define input parameter pEffDate as date no-undo.
   define parameter buffer pPod_det for pod_det.
   define buffer schd_det for schd_det .
   do on error undo, return error {&GENERAL-APP-EXCEPT}:

      assign
         pDivisor  = 0
         pOpenQty = 0.

      {pxrun.i &PROC='readLastScheduleDetail' &PROGRAM='rsscxr1.p'
                &HANDLE=ph_rsscxr1
               &PARAM="(input pod_nbr,
                        input pod_line,
                        input pEffDate,
                        input pod_curr_rlse_id[1],
                        buffer schd_det,
                        input {&NO_LOCK_FLAG},
                        input {&NO_WAIT_FLAG})"}

      if available schd_det then do:
         assign
            pOpenQty = max(schd_cum_qty - pod_cum_qty[1],0)
            pDivisor  = schd_discr_qty.
      end. /* IF AVAILABLE SCHD_DET */
      else do:

         {pxrun.i &PROC='processRead'
                  &PARAM="(input pod_nbr,
                           input pod_line,
                           input pod_curr_rlse_id[1],
                           buffer sch_mstr,
                           input {&NO_LOCK_FLAG},
                           input {&NO_WAIT_FLAG})"}

         if return-value = {&SUCCESS-RESULT} then do:
            assign
               pOpenQty = max(sch_pcr_qty - pod_cum_qty[1],0)
               pDivisor  = pOpenQty.
         end. /* IF AVAILABLE SCH_MSTR */
      end. /* ELSE DO: */
   end.
   return {&SUCCESS-RESULT}.
END PROCEDURE.


/*mtt*/
/*============================================================================*/
PROCEDURE processRead :
/*------------------------------------------------------------------------------
<Comment1>
rsscxr.p
processRead (
   input character pPurchaseOrderId,
   input integer pPurchaseOrderLineId,
   input character pReleaseId,
    Buffer pSch_Mstr,
   input logical pLock,
   input logical pWait)

Parameters:
   pPurchaseOrderId -
   pPurchaseOrderLineId -
   pReleaseId -
   pSch_Mstr -
   pLock -
   pWait -

Exceptions:

PreConditions:

PostConditions:

</Comment1>
<Comment2>
Notes:

</Comment2>
<Comment3>
History:

</Comment3>
------------------------------------------------------------------------------*/
   define input parameter pPurchaseOrderId as character no-undo.
   define input parameter pPurchaseOrderLineId as integer no-undo.
   define input parameter pReleaseId as character no-undo.
   define  parameter buffer pSch_Mstr for sch_mstr.
   define input parameter pLock as logical no-undo.
   define input parameter pWait as logical no-undo.

   do on error undo, return error {&GENERAL-APP-EXCEPT}:

      if pLock then do:
         if pWait then
            find first pSch_Mstr
               where sch_type     = 4
               and sch_nbr      = pPurchaseOrderId
               and sch_line     = pPurchaseOrderLineId
               and sch_rlse_id  = pReleaseId
            exclusive-lock no-error .
         else do :
            find first pSch_Mstr
               where sch_type     = 4
               and sch_nbr      = pPurchaseOrderId
               and sch_line     = pPurchaseOrderLineId
               and sch_rlse_id  = pReleaseId
            exclusive-lock no-wait no-error .
            if locked pSch_Mstr then
               return {&RECORD-LOCKED}.
         end.
      end.
      else
         find first pSch_Mstr
            where sch_type     = 4
            and sch_nbr      = pPurchaseOrderId
            and sch_line     = pPurchaseOrderLineId
            and sch_rlse_id  = pReleaseId
            no-lock no-error .
      if not available pSch_Mstr then
         return {&RECORD-NOT-FOUND} .
   end.
   return {&SUCCESS-RESULT}.
END PROCEDURE.
